/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package buttontimer;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Font;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.util.Timer;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class ButtonTimer extends JFrame implements Runnable {

    private JLabel lblTime = null;
    private JTextField btnTime = null;

    public static final void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new ButtonTimer();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
            }
        });
    }

    public ButtonTimer() {
        setTitle("Time ");
        setLayout(new FlowLayout());
        lblTime = new JLabel("Time: ");
        btnTime = new JTextField(new Date(System.currentTimeMillis()).toString());
        btnTime.setSize(100, 200);
        add(lblTime);
        add(btnTime);
        pack();
        
        Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this, 1000, 1000, TimeUnit.MILLISECONDS);
      
    }
private void changeFont(Container cont)
 {
  // все компоненты swing являются контейнерами
  Component [] comps = cont.getComponents();
  Font f = new Font("serif", Font.PLAIN, 40);

 }

    public void run() {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                btnTime.setText(new Date(System.currentTimeMillis()).toString());
               String str="kk";
                Date date=new Date();
               System.out.println(date.getSeconds());
               if(date.getSeconds()>=5&& date.getSeconds()<=30)
               {
               System.out.println("Hei!");
                Font f=new Font("",Font.BOLD,50);
                SwingUtilities.updateComponentTreeUI(btnTime);

                f.deriveFont(200);
 btnTime.setBackground(Color.BLUE);
 btnTime.setSize(200, 100);
               }
 else
               {
                   btnTime.setBackground(Color.red);
                Font f = new Font("plain", Font.PLAIN, 20);
                f.deriveFont(20);
                SwingUtilities.updateComponentTreeUI(btnTime);
               }
                
            }
        });
    }
}